package dbopr

import (
	"myCloud/dbmodel"
)

type ServerProvider struct{}

func NewServerProvider() *ServerProvider {
	return &ServerProvider{}
}

func (*ServerProvider) Get() (*dbmodel.ServerInfo, error) {
	var out dbmodel.ServerInfo
	err := dbSession.First(&out).Error
	return &out, err
}

func (*ServerProvider) Init(idGenerator func() string) (*dbmodel.ServerInfo, error) {
	var out dbmodel.ServerInfo

	err := dbSession.Attrs(dbmodel.ServerInfo{
		ServerID: idGenerator(),
	}).FirstOrCreate(&out).Error

	return &out, err
}
